<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@include file="../WEB-INF/jspf/controlesessao.jspf"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Consultar Turmas</title>
        <script type="text/javascript" src="../js/jquery.js" ></script>
        <script type="text/javascript" src="../js/jquery.validate.js"></script>
        <script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js" ></script>
        <script type="text/javascript" src="../js/jquery.ui.datepicker-pt-BR.js" ></script>
        <script type="text/javascript" src="../js/jquery.tablescroll.js"></script>
        <script type="text/javascript" src="../js/forms.js"></script>
        <script type="text/javascript" src="../js/alocacao.js"></script>
        <link rel="stylesheet" href="../css/ui-lightness/jquery-ui-1.8.2.custom.css">
        <link rel="stylesheet" href="../css/forms.css">
    </head>
    <script>
        $(function() {
            $("#procurar").button();
            $("#executar").button();

            $("#procurar").click(function() {
                getTurmasCalendario($("form"));
            });
            $("#nova").click(function() {
                document.form.action='fm_new_turmas.jsp?token=${sessionScope.token}';
                document.form.submit();
            });

            $("#all").live("click", function(){
                var checked_status = this.checked;
                $("input[name=id_turma]").each(function()
                {
                    this.checked = checked_status;
                });

            });

            $("#executar").click(function(){
                $("#processando").dialog('open');
                $("#processando").html('<p>Processando...aguarde...</p><img src="../imagens/loading.gif" width="48" height="48" alt="Loading"/>');

                $("#exec").html('');
                $("input[name=id_turma]:checked").each(function(){
                    $("#exec").append('<input name="id_turma" type="hidden" value="'+ $(this).val() + '"');
                });
                processar();
            });

            $("#processando").dialog({
                autoOpen:false,
                resizable: true,
                height: 340,
                width:440,
                modal: true,
                buttons: {                    
                    Fechar: function() {
                        $(this).dialog('close');
                    }
                }
            });

        });

        $(function() {
            var dates = $('#data_inicio, #data_fim').datepicker({
                defaultDate: "+1w",
                changeMonth: true,
                numberOfMonths: 3,
                onSelect: function(selectedDate) {
                    var option = this.id == "data_inicio" ? "minDate" : "maxDate";
                    var instance = $(this).data("datepicker");
                    var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                    dates.not(this).datepicker("option", option, date);
                }
            });
        });
        function processar(){
            var params = $("#exec").serialize();
            $.ajax({
                url: "reestruturar_turma.jsp?token=${sessionScope.token}",
                type: "POST",
                data: params,
                async:true,
                success:mensagem
            });
        }
        function mensagem(data){
            $("#processando").html(data);
        }
    </script>
    <body>
        <div id="formulario">
            <h1>Turmas para reprocessamento</h1>
            <form name="form" id="form" method="post" action="fm_lista_turmas.jsp">
                <p><label class="lbInput">Período</label>
                    <input type="text" id="data_inicio" name="data_inicio" size="12" value="${param.data_inicio}" maxlength="12" class="required">
                    <label class="lbInput">a</label>
                    <input type="text" id="data_fim" name="data_fim" size="12" maxlength="12" value="${param.data_fim}" class="required">
                </p>
                <p>
                    <label>Situação da turma</label>
                    <select name="situacao_turma">                       
                        <option value="D"> Aguardando Alocação de docentes</option>
                        <option value="R"> Liberadas para cadastro </option>                       
                        <option value="G"> Liberadas para o gestor</option>
                    </select>
                </p>
            <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>
            <form name="exec" id="exec" method="post" action="reestruturar_turma.jsp">

            <input type="hidden" id="token" name="token" value="${sessionScope.token}" /> </form>

            <br>
            <br>
            <br>
            <button id="procurar">Procurar</button>
            <button id="executar">Estruturar turmas</button>
            <div id="turmas">
            </div>

        </div>
        <div id="processando" title="Processando">            
        </div>
    </body>
</html>
